/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.dao;


import core.APersistenceManager;
import core.ITeamDAO;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import persistence.*;
import validators.TeamValidator;

/**
 *
 * @author Ivan
 */

public class TeamDAO extends APersistenceManager<Team> implements ITeamDAO {

    public TeamDAO() {
        super(Team.class, new TeamValidator());
    }

    @Override
    public Rating getRating(int idTeam) {
        Team team = getEntityManager().find(Team.class, BigDecimal.valueOf(idTeam));
        return team.getRatingId();
    }

    @Override
    public Set<Team> getTeamsByDiscipline(int idDiscipline) {
        Discipline discipline = getEntityManager().find(Discipline.class, BigDecimal.valueOf(idDiscipline));
        return discipline.getTeamSet();
    }

    @Override
    public Set<Team> getTeamsByGame(int idGame) {
        Set<Team> teams = new HashSet<Team>();
        Game game = getEntityManager().find(Game.class, BigDecimal.valueOf(idGame));
        for(GameContract gc : game.getGameContractSet()){
          teams.add(gc.getTeamId());
        }
        return teams;
    }

    @Override
    public Set<Team> getTeamsByOwner(int idUser) {
          SysUser sysUser = getEntityManager().find(SysUser.class, BigDecimal.valueOf(idUser));
           return sysUser.getTeamSet();
    }

    @Override
    public Set<Team> getTeamsByPlayer(int idPlayer) {
        Set<Team> teams = new HashSet<Team>();
        Player player = getEntityManager().find(Player.class, BigDecimal.valueOf(idPlayer));
        for(TeamContract tc : player.getTeamContractSet()){
          teams.add(tc.getTeamId());
        }
        return teams;
    }

    @Override
    public void changeRating(int idTeam, Rating r) {
         ///maybe it don't need. simple do it through the edit parent method
    }
    
    
    
    
}
